package br.com.moxeon.control.operation.rules;

import java.util.ArrayList;
import java.util.Date;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import br.com.moxeon.model.cash.Throw;
import br.com.moxeon.model.financialitems.Check;

@Service
@Scope("prototype")
public class SingleThrowRule extends FinancialRule {

	@Override
	public void executeOperation() {
		super.executeOperation();
		getOperation().setPayableAccounts(null);
		getOperation().setReceivableAccounts(null);
		///TODO Métodos genéricos de operação de cheque
		Throw financialThrow = (Throw) getData().get("throw");
		if( financialThrow.getItem() instanceof Check)
		{
			Check check = (Check) financialThrow.getItem();
			check.setValue(financialThrow.getValue());
			check.setMaturity( (Date)getData().get("checkMaturity") );
			check.setIssueDate( (Date)getData().get("issueDate") );
		}
		if (financialThrow.getItem() != null) {
			financialThrow.getItem().setFinancialThrow(financialThrow);
		}
		ArrayList<Throw> financialThrows = new ArrayList<Throw>();
		financialThrows.add(financialThrow);
		getOperation().setListThorws(financialThrows);
		financialThrow.setOperation(getOperation());
		finalizeOperation();
	}
	
	@Override
	public void reverseOperation() {
		
	}

	
}
